﻿using SRB.Tg.Common;
using SRB.Tg.DrawingStandard;
using SRB.Tg.Operate;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using Teigha.DatabaseServices;
using Teigha.Geometry;

namespace SRB.Tg.Model
{
    public class DrawingSteelTrussStructure
    {

        //BridgeStructureType bridge_type = BridgeStructureType.AviationBridge;
        string _type = "0";
        System.Data.DataTable dtProject = new System.Data.DataTable();
        System.Data.DataTable dtBridge = new System.Data.DataTable();
        System.Data.DataTable dtBridgeDrawing = new System.Data.DataTable();
        System.Data.DataTable dtProjectConfig = new System.Data.DataTable();
        string _bridgeId = null;
        DrawingConfigModel drawingConfigModel = new DrawingConfigModel();
        bool isDL = false;
        public DrawingSteelTrussStructure(string bridgeId, string type,out System.Data.DataTable dtProjectTb,bool isMerge = false)
        {
            _type = type;
            #region  参数数据初始化
            dtBridgeDrawing = new System.Data.DataTable();//图纸目录信息表
            //传入bridgeId，查询出mainId
            string sqlMainId = "select * from busi_bridge where id='" + bridgeId + "' ";
            if (bridgeId == "1802595897232498690")
                isDL = true;
            string mainId = MySqlHelper.ExecuteDataTable(sqlMainId, CommandType.Text).Rows[0]["main_id"].ToString();
            _bridgeId = mainId;
            string sqlBridge = "select * from busi_bridge_main where id='" + mainId + "'";
            dtBridge = MySqlHelper.ExecuteDataTable(sqlBridge, CommandType.Text);

            int bridge_scope = 1;//桥幅（单幅桥和双幅桥）
            if (dtBridge.Rows.Count > 0)
            {
                bridge_scope = int.Parse(dtBridge.Rows[0]["bridge_scope"].ToString());
                if (bridge_scope > 0)
                    isMerge = dtBridge.Rows[0]["drawing_level"].ToString() == "1" ? true : false; //双幅桥图纸是否合并
            }


            string sqlDrawing = "select * from busi_bridge_catalog where  bridge_main_id='" + mainId + "'";
            dtBridgeDrawing = MySqlHelper.ExecuteDataTable(sqlDrawing, CommandType.Text);
            #endregion

            dtProjectTb = dtBridgeDrawing;
        }
        public void DrawingSteelTrussBeamCAD(Database db, int OverAllScale, string bridgeId, out System.Data.DataTable dtProjectConfigTb,string catalogid)
        {
            try
            {
                string sqlBridge = "select * from vi_bridge where  id='" + _bridgeId + "'";
                System.Data.DataTable dtAviationBridgeInfo = MySqlHelper.ExecuteDataTable(sqlBridge, CommandType.Text);
                double bridgeLength = 0;
                if (dtAviationBridgeInfo.Rows.Count>0)
                {
                    bridgeLength = double.Parse(dtAviationBridgeInfo.Rows[0]["bridge_length"].ToString());
                }
                string sqlBridgeConfig = "select * from busi_project_config where bridge_id='" + bridgeId + "'";
                dtProjectConfig = MySqlHelper.ExecuteDataTable(sqlBridgeConfig, CommandType.Text);
                PictureFrameTools.GetBridgeConfig(dtProjectConfig);
                drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtBridgeDrawing, catalogid, dtProjectConfig);
                OverAllScale = drawingConfigModel.drawing_scale;
                int count = (int)bridgeLength/ 200;

                int divCount = bridgeLength / 200> count? count+1: count;
                switch (_type)
                {
                    case "0":
                        #region 绘制图形
                    

                        Extents2d ExtBridgeE;
                        Point2d RefPtBridgeE;
                        RefPtBridgeE = Point2d.Origin;

                        DrawingSteelTrussBeam bridge = new DrawingSteelTrussBeam(_bridgeId, OverAllScale);
                        Point2d RefPt;
                        DrawingSteelTrussBeam.PlotSteelTrussBeamNew(ref db, out ExtBridgeE, RefPtBridgeE, out RefPt);

                        #endregion
                        List<Extents2d> extLst = new List<Extents2d>();
                        if (divCount == 1)
                            extLst.Add(ExtBridgeE);
                        else
                        {
                            for (int i = 1; i < divCount; i++)
                            {
                                if (i < divCount)
                                {
                                    Point2d ptMin = ExtBridgeE.GetDivMin(i, divCount);
                                    Point2d ptMax = ExtBridgeE.GetDivMax(i, divCount);
                                    Extents2d ext = new Extents2d(ptMin, ptMax);
                                    extLst.Add(ext);
                                }
                                if(i == divCount - 1)
                                {
                                    Point2d ptMin = ExtBridgeE.GetDivMin(i+1, divCount);
                                    Point2d ptMax = ExtBridgeE.GetDivMax(i+1, divCount);
                                    Extents2d ext = new Extents2d(ptMin, ptMax);
                                    extLst.Add(ext);
                                }
                            }
                        }
                        #region 模型空间到布局空间投影处理
                   
                        LayoutTools.CreateTrussBeamStructureLayout(db, "图纸", extLst,   Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, OverAllScale,  0);
                        Point2d tKPoint = Point2d.Origin;
                        double h = extLst[extLst.Count - 1].L()/ OverAllScale;
                        double w = extLst[extLst.Count - 1].W() / OverAllScale + 5;
                        double hTK = ((297 - Extensions.bottomHeight - Extensions.topHeight) - 20)/divCount;
                        double wTK = 420 - Extensions.leftWidth - Extensions.rightWidth;
                        Extents2d extT = new Extents2d(Point2d.Origin, Point2d.Origin);
                        Point2d pt = Point2d.Origin.C2D(Extensions.leftWidth + (420 - Extensions.leftWidth - Extensions.rightWidth) * 0.5, Extensions.bottomHeight + (297 - Extensions.bottomHeight - Extensions.topHeight) - h*0.1-10);
                        TextPloter.AddTitleToPaper(db, pt, ref extT, "钢桁架立面", "",1);
                        if (divCount > 1)
                        {
                            for (int i = 0; i < divCount; i++)
                            {
                                if (i == 0)
                                {
                                    Point2d ptB = Point2d.Origin.C2D(Extensions.leftWidth + 5 + wTK * 0.5 - w * 0.5, Extensions.bottomHeight + hTK * (0.5) + 0.5 * h);
                                    if(divCount==3)
                                       PLPloter.CreateBreakLineP2PaPer(db, ref extT, ptB.C2D(0, -h * 0.05), ptB.C2D(0, -h * 0.2 - 10), 1, "H细线");
                                    else
                                        PLPloter.CreateBreakLineP2PaPer(db, ref extT, ptB.C2D(0, -h * 0.05), ptB.C2D(0, -h * 0.2 - 10), 1, "H细线");
                                }
                                else if (i == divCount-1)
                                {
                                    Point2d ptB = Point2d.Origin.C2D(Extensions.leftWidth + 5 + wTK * 0.5 + w * 0.5, Extensions.bottomHeight + hTK * (extLst.Count - 0.5) + 0.5 * h);
                                    if (divCount == 3)
                                        PLPloter.CreateBreakLineP2PaPer(db, ref extT, ptB.C2D(0, -h * 0.1), ptB.C2D(0, -h * 0.25 - 10), 1, "H细线");
                                   else
                                        PLPloter.CreateBreakLineP2PaPer(db, ref extT, ptB.C2D(0, -h * 0.1), ptB.C2D(0, -h * 0.25 - 10), 1, "H细线");
                                }
                                else // if(i>0&&i< divCount - 1)
                                {
                                    Point2d ptBL = Point2d.Origin.C2D(Extensions.leftWidth + 5 + wTK * 0.5 - w * 0.5, Extensions.bottomHeight + hTK * (i + 0.5) + 0.5 * h);
                                    PLPloter.CreateBreakLineP2PaPer(db, ref extT, ptBL.C2D(0, -h * 0.1), ptBL.C2D(0, -h * 0.3 - 10), 1, "H细线");
                                    Point2d ptBR = Point2d.Origin.C2D(Extensions.leftWidth + 5 + wTK * 0.5 + w * 0.5, Extensions.bottomHeight + hTK * (i+0.5) + 0.5 * h);
                                    PLPloter.CreateBreakLineP2PaPer(db, ref extT, ptBR.C2D(0, -h * 0.1), ptBR.C2D(0, -h * 0.3 - 10), 1, "H细线");
                                }
                            }
                        }
                        string text = @"注
 1.本图尺寸均以厘米为单位。";
                        Point3d p = Point2d.Origin.C3D(Extensions.leftWidth + (420 - Extensions.leftWidth - Extensions.rightWidth) * 0.8, Extensions.bottomHeight +  15);
                        TextPloter.AddMText2Paper(db, p, ref extT, text, 1, 2.5, OverAllScale, Extensions.curFont);

                        Extents2d ex = new Extents2d();
                        PictureFrameTools.AddPaperDBText(db, tKPoint, 0, drawingConfigModel, ref ex,   1, 1);

                        #endregion


                        break;

                    case "1":
                        #region 绘制图形
                        //drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtBridgeDrawing, catalogid, dtProjectConfig);
                        //OverAllScale = drawingConfigModel.drawing_scale;

                        Extents2d ExtE;
                        Point2d RefPtE;
                        RefPtE = Point2d.Origin;

                        DrawingSteelTrussBeam bridgeBeam = new DrawingSteelTrussBeam(_bridgeId, OverAllScale);
                        Point2d RefPt1;
                        DrawingSteelTrussBeam.PlotSteelTrussBeamPreRrch(ref db, out ExtE, RefPtE, out RefPt1);

                        #endregion
                        List<Extents2d> extArcLst = new List<Extents2d>();
                        if (divCount == 1)
                            extArcLst.Add(ExtE);
                        else
                        {
                            for (int i = 1; i < divCount; i++)
                            {
                                if (i < divCount)
                                {
                                    Point2d ptMin = ExtE.GetDivMin(i, divCount);
                                    Point2d ptMax = ExtE.GetDivMax(i, divCount);
                                    Extents2d ext = new Extents2d(ptMin, ptMax);
                                    extArcLst.Add(ext);
                                }
                                if (i == divCount - 1)
                                {
                                    Point2d ptMin = ExtE.GetDivMin(i + 1, divCount);
                                    Point2d ptMax = ExtE.GetDivMax(i + 1, divCount);
                                    Extents2d ext = new Extents2d(ptMin, ptMax);
                                    extArcLst.Add(ext);
                                }
                            }
                        }
                        #region 模型空间到布局空间投影处理
                        LayoutTools.CreateTrussBeamStructureLayout(db, "图纸", extArcLst, Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, OverAllScale, 0);
                        Point2d tKPoint1 = Point2d.Origin;

                        double h1 = extArcLst[extArcLst.Count - 1].L() / OverAllScale;
                        Extents2d extT1 = new Extents2d(Point2d.Origin, Point2d.Origin);
                        Point2d pt1 = Point2d.Origin.C2D(Extensions.leftWidth + (420 - Extensions.leftWidth - Extensions.rightWidth) * 0.5, Extensions.bottomHeight + (297 - Extensions.bottomHeight - Extensions.topHeight) - h1 * 0.2 - 10);
                        TextPloter.AddTitleToPaper(db, pt1, ref extT1, "钢桁梁预拱度设置", "", 1);

                        string text1 = @"注
 1.本图尺寸均以毫米为单位。
 2.预拱度值是按一次成桥考虑，可根据施工顺序进行调整";
                        Point3d p1 = Point2d.Origin.C3D(Extensions.leftWidth + (420 - Extensions.leftWidth - Extensions.rightWidth) * 0.78, Extensions.bottomHeight + 15);
                        TextPloter.AddMText2Paper(db, p1, ref extT1, text1, 1, 2.5, OverAllScale, Extensions.curFont);

                        Extents2d ex1 = new Extents2d();
                        PictureFrameTools.AddPaperDBText(db, tKPoint1, 0, drawingConfigModel, ref ex1, 1, 1);

                        #endregion

                        break;
                }
            }
            catch (Exception ex)
            {

            }
            dtProjectConfigTb = dtProjectConfig;
        }

        public void DrawingSteelTrussBeamByGL(Database db, string bridgeId, string categoryId, int page, int count, out System.Data.DataTable dtProjectConfigTb, double bridgeW,double bridgeSlope, double divCap,double divHeight,double glLen,string glName, DataRow dr,double divCapLast=0)
        {
            try
            {
                string sqlBridgeConfig = "select * from busi_project_config where bridge_id='" + bridgeId + "'";
                dtProjectConfig = MySqlHelper.ExecuteDataTable(sqlBridgeConfig, CommandType.Text);
                PictureFrameTools.GetBridgeConfig(dtProjectConfig);
              

                Line lineD = new Line();
                Line lineD0 = new Line();

                Point2d dPt1 = Point2d.Origin;
                List<Tuple<double, double, double>> tupleLst = new List<Tuple<double, double, double>>();


                #region 绘制图形
                drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtBridgeDrawing, categoryId, dtProjectConfig);
                double OverAllScale = drawingConfigModel.drawing_scale;
                DrawingSteelTrussBeam bridge = new DrawingSteelTrussBeam(_bridgeId, OverAllScale);
         
                Extents2d Ext, ExtNote;
                Point2d RefPt, RefPtNote;
                RefPt = Point2d.Origin;
                Ext = new Extents2d();
                DrawingSteelTrussBeam.PlotSteelTrussBeamStructure(ref db, out Ext, RefPt, bridgeW, bridgeSlope, divCap, divHeight, glLen, glName,dr);
                ExtNote = new Extents2d();


                #endregion

                #region 模型空间到布局空间投影处理
                LayoutTools.CreateLayoutNew(db, "图纸", Ext, Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, OverAllScale);
                Point2d tKPoint = Point2d.Origin;

                Extents2d ex = new Extents2d();
                //PictureFrameTools.AddPaperDBText(db, tKPoint, drawingConfigModel, ref ex, exfLst.Count);
                PictureFrameTools.AddPaperDBText(db, tKPoint, 0, drawingConfigModel, ref ex, page, count);
                #endregion


            }
            catch (Exception ex)
            {

            }
            dtProjectConfigTb = dtProjectConfig;
        }

        public void DrawingSteelTrussBeamByGL(Database db, string bridgeId, string categoryId, int page, int count, out System.Data.DataTable dtProjectConfigTb, double bridgeW, double bridgeSlope, double divCap, double divHeight, List<Tuple<string, double, double, DataRow,bool>> tupGLLst)
        {
            try
            {
                string sqlBridgeConfig = "select * from busi_project_config where bridge_id='" + bridgeId + "'";
                dtProjectConfig = MySqlHelper.ExecuteDataTable(sqlBridgeConfig, CommandType.Text);
                PictureFrameTools.GetBridgeConfig(dtProjectConfig);


                Line lineD = new Line();
                Line lineD0 = new Line();

                Point2d dPt1 = Point2d.Origin;
                List<Tuple<double, double, double>> tupleLst = new List<Tuple<double, double, double>>();


                #region 绘制图形
                drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtBridgeDrawing, categoryId, dtProjectConfig);
                double OverAllScale = drawingConfigModel.drawing_scale;
                double lenGL = tupGLLst[page - 1].Item2;
                if (page < tupGLLst.Count - 1)
                    lenGL = tupGLLst[page].Item2 > lenGL ? tupGLLst[page].Item2 : lenGL;
                //if (lenGL >= 10 * 1000)
                    OverAllScale = 80;
                //else
                    //OverAllScale = 60;
                DrawingSteelTrussBeam bridge = new DrawingSteelTrussBeam(_bridgeId, OverAllScale);

                Extents2d Ext, ExtNote;
                Point2d RefPt, RefPtNote;
                RefPt = Point2d.Origin;
                Ext = new Extents2d();
                DrawingSteelTrussBeam.PlotSteelTrussBeamStructure(ref db, out Ext, RefPt, bridgeW, bridgeSlope, divCap, divHeight, tupGLLst, (page-1)*2, isDL);
                //ExtNote = new Extents2d();

                //DrawingSteelTrussBeam.DrawingGLTable(ref db, ref ExtNote, RefPt, bridgeW, bridgeSlope, divCap, divHeight, tupGLLst);
                #endregion

                #region 模型空间到布局空间投影处理
                LayoutTools.CreateLayoutNew(db, "图纸", Ext, Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, OverAllScale);
                Point2d tKPoint = Point2d.Origin;


                Extents2d extT1 = new Extents2d(Point2d.Origin, Point2d.Origin);
                string text1 = @"注
 1.本图尺寸均以毫米为单位。
 2.检修道及护栏构造另见详图";
                Point3d p1 = Point2d.Origin.C3D(Extensions.leftWidth + (420 - Extensions.leftWidth - Extensions.rightWidth) * 0.78, Extensions.bottomHeight + 15);
                TextPloter.AddMText2Paper(db, p1, ref extT1, text1, 1, 2.5, OverAllScale, Extensions.curFont);


                Extents2d ex = new Extents2d();
                //PictureFrameTools.AddPaperDBText(db, tKPoint, drawingConfigModel, ref ex, exfLst.Count);
                PictureFrameTools.AddPaperDBText(db, tKPoint, 0, drawingConfigModel, ref ex, page, count);
                #endregion


            }
            catch (Exception ex)
            {

            }
            dtProjectConfigTb = dtProjectConfig;
        }

        public void DrawingSteelTrussBeamByGLExtend(Database db, string bridgeId, string categoryId, int page, int count, out System.Data.DataTable dtProjectConfigTb, double bridgeW, double bridgeSlope, double divCap, double divHeight, List<Tuple<string, double, double, DataRow, bool>> tupGLLst, double divCapLast = 0)
        {
            try
            {
                string sqlBridgeConfig = "select * from busi_project_config where bridge_id='" + bridgeId + "'";
                dtProjectConfig = MySqlHelper.ExecuteDataTable(sqlBridgeConfig, CommandType.Text);
                PictureFrameTools.GetBridgeConfig(dtProjectConfig);


                Line lineD = new Line();
                Line lineD0 = new Line();

                Point2d dPt1 = Point2d.Origin;
                List<Tuple<double, double, double>> tupleLst = new List<Tuple<double, double, double>>();


                #region 绘制图形
                drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtBridgeDrawing, categoryId, dtProjectConfig);
                double OverAllScale = drawingConfigModel.drawing_scale;
                //double lenGL = tupGLLst[page - 1].Item2;
                //if (page < tupGLLst.Count - 1)
                //    lenGL = tupGLLst[page].Item2 > lenGL ? tupGLLst[page].Item2 : lenGL;
                //if (lenGL >= 10 * 1000)
                    OverAllScale = 80;
                //else
                //    OverAllScale = 60;
                DrawingSteelTrussBeam bridge = new DrawingSteelTrussBeam(_bridgeId, OverAllScale);

                Extents2d Ext, ExtNote;
                Point2d RefPt, RefPtNote;
                RefPt = Point2d.Origin;
                Ext = new Extents2d();
               
                DrawingSteelTrussBeam.PlotSteelTrussBeamStructureExtend(ref db, out Ext, RefPt, bridgeW, bridgeSlope, divCap, divHeight, tupGLLst,0, divCapLast);
              
                //ExtNote = new Extents2d();

                //DrawingSteelTrussBeam.DrawingGLTable(ref db, ref ExtNote, RefPt, bridgeW, bridgeSlope, divCap, divHeight, tupGLLst);
                #endregion

                #region 模型空间到布局空间投影处理
                LayoutTools.CreateLayoutNew(db, "图纸", Ext, Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, OverAllScale);
                Point2d tKPoint = Point2d.Origin;

                double h = Ext.L() / OverAllScale;
                Extents2d extT1 = new Extents2d(Point2d.Origin, Point2d.Origin);
                string text1 = @"注
 1.本图尺寸均以毫米为单位。
 2.检修道及护栏构造另见详图";
                Point3d p1 = Point2d.Origin.C3D(Extensions.leftWidth + (420 - Extensions.leftWidth - Extensions.rightWidth) * 0.6, Extensions.bottomHeight + h*0.5);
                TextPloter.AddMText2Paper(db, p1, ref extT1, text1, 1, 2.5, OverAllScale, Extensions.curFont);


                Extents2d ex = new Extents2d();
                //PictureFrameTools.AddPaperDBText(db, tKPoint, drawingConfigModel, ref ex, exfLst.Count);
                PictureFrameTools.AddPaperDBText(db, tKPoint, 0, drawingConfigModel, ref ex, page, count);
                #endregion


            }
            catch (Exception ex)
            {

            }
            dtProjectConfigTb = dtProjectConfig;
        }



        public void DrawingSteelTrussBeamGLTable(Database db, string bridgeId, string categoryId, int page, int count, out System.Data.DataTable dtProjectConfigTb, double bridgeW, double bridgeSlope, double divCap, double divHeight, Dictionary<Tuple<string, double, double, DataRow, bool>, int> dicGL, ref System.Data.DataTable dtQuatity, int stNum = 0,double divCapLast=0)
        {
            try
            {
                string sqlBridgeConfig = "select * from busi_project_config where bridge_id='" + bridgeId + "'";
                dtProjectConfig = MySqlHelper.ExecuteDataTable(sqlBridgeConfig, CommandType.Text);
                PictureFrameTools.GetBridgeConfig(dtProjectConfig);


                Point2d dPt1 = Point2d.Origin;
                List<Tuple<double, double, double>> tupleLst = new List<Tuple<double, double, double>>();


                #region 绘制图形
                drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtBridgeDrawing, categoryId, dtProjectConfig);
                double OverAllScale = drawingConfigModel.drawing_scale;
                DrawingSteelTrussBeam bridge = new DrawingSteelTrussBeam(_bridgeId, OverAllScale);

                Extents2d ExtNote;
                Point2d RefPtNote;
                RefPtNote = Point2d.Origin;
                ExtNote = new Extents2d(RefPtNote, RefPtNote);


                DrawingSteelTrussBeam.DrawingGLTable(ref db, ref ExtNote, RefPtNote, bridgeW, bridgeSlope, divCap, divHeight, dicGL,ref dtQuatity, stNum, divCapLast);
                #endregion

                #region 模型空间到布局空间投影处理
                LayoutTools.CreateLayoutNew(db, "图纸", ExtNote, Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, 1);
                Point2d tKPoint = Point2d.Origin;

                Extents2d ex = new Extents2d();
                //PictureFrameTools.AddPaperDBText(db, tKPoint, drawingConfigModel, ref ex, exfLst.Count);
                PictureFrameTools.AddPaperDBText(db, tKPoint, 0, drawingConfigModel, ref ex, page, count);
                #endregion


            }
            catch (Exception ex)
            {

            }
            dtProjectConfigTb = dtProjectConfig;
        }

        public void DrawingSteelTrussBeamByAverageGL(Database db, string bridgeId, string categoryId, int page, int count, out System.Data.DataTable dtProjectConfigTb, double bridgeW, double bridgeSlope, double divCap, double divHeight, List<Tuple<string, double, double, DataRow, bool, double>> tupGLLst, List<Tuple<string, double>> tupleGLLst, double light_width = 4500, double leftExt = 0, double rightExt = 0)
        {
            try
            {
                string sqlBridgeConfig = "select * from busi_project_config where bridge_id='" + bridgeId + "'";
                dtProjectConfig = MySqlHelper.ExecuteDataTable(sqlBridgeConfig, CommandType.Text);
                PictureFrameTools.GetBridgeConfig(dtProjectConfig);


                Line lineD = new Line();
                Line lineD0 = new Line();

                Point2d dPt1 = Point2d.Origin;
                List<Tuple<double, double, double>> tupleLst = new List<Tuple<double, double, double>>();


                #region 绘制图形
                drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtBridgeDrawing, categoryId, dtProjectConfig);
                double OverAllScale = drawingConfigModel.drawing_scale;
                double lenGL = tupGLLst[page - 1].Item2;
                if(page< tupGLLst.Count-1)
                lenGL = tupGLLst[page ].Item2> lenGL? tupGLLst[page].Item2: lenGL;
                if (lenGL >= 10 * 1000)
                    OverAllScale = 80;
                else
                    OverAllScale = 60;
                DrawingSteelTrussBeam bridge = new DrawingSteelTrussBeam(_bridgeId, OverAllScale);

                Extents2d Ext, ExtNote;
                Point2d RefPt, RefPtNote;
                RefPt = Point2d.Origin;
                Ext = new Extents2d();
                DrawingSteelTrussBeam.PlotSteelTrussBeamStructureAverage(ref db, out Ext, RefPt, bridgeW, bridgeSlope, divCap, divHeight, tupGLLst,tupleGLLst, (page - 1), light_width,leftExt,rightExt);
                //ExtNote = new Extents2d();

                //DrawingSteelTrussBeam.DrawingGLTable(ref db, ref ExtNote, RefPt, bridgeW, bridgeSlope, divCap, divHeight, tupGLLst);
                #endregion

                #region 模型空间到布局空间投影处理
                LayoutTools.CreateLayoutNew(db, "图纸", Ext, Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, OverAllScale);

                double h = Ext.L() / OverAllScale;
                Point2d tKPoint = Point2d.Origin;


                Extents2d extT1 = new Extents2d(Point2d.Origin, Point2d.Origin);
                string text1 = @"注
 1.本图尺寸均以毫米为单位。
 2.检修道及护栏构造另见详图";
                Point3d p1 = Point2d.Origin.C3D(Extensions.leftWidth + (420 - Extensions.leftWidth - Extensions.rightWidth) * 0.78, Extensions.bottomHeight + (297 - Extensions.bottomHeight - Extensions.topHeight)*0.5 - h * 0.5);
                TextPloter.AddMText2Paper(db, p1, ref extT1, text1, 1, 2.5, OverAllScale, Extensions.curFont);


                Extents2d ex = new Extents2d();
                //PictureFrameTools.AddPaperDBText(db, tKPoint, drawingConfigModel, ref ex, exfLst.Count);
                PictureFrameTools.AddPaperDBText(db, tKPoint, 0, drawingConfigModel, ref ex, page, count);
                #endregion


            }
            catch (Exception ex)
            {

            }
            dtProjectConfigTb = dtProjectConfig;
        }

        public void DrawingSteelTrussBeamAverageGLNote(Database db, string bridgeId, string categoryId, int page, int count, out System.Data.DataTable dtProjectConfigTb, int stNum = 1)
        {
            try
            {
                string sqlBridgeConfig = "select * from busi_project_config where bridge_id='" + bridgeId + "'";
                dtProjectConfig = MySqlHelper.ExecuteDataTable(sqlBridgeConfig, CommandType.Text);
                PictureFrameTools.GetBridgeConfig(dtProjectConfig);


                Point2d dPt1 = Point2d.Origin;
                List<Tuple<double, double, double>> tupleLst = new List<Tuple<double, double, double>>();


                #region 绘制图形
                drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtBridgeDrawing, categoryId, dtProjectConfig);
                double OverAllScale = 1;
                DrawingSteelTrussBeam bridge = new DrawingSteelTrussBeam(_bridgeId, OverAllScale);

                Extents2d ExtNote;
                Point2d RefPtNote;
                RefPtNote = Point2d.Origin;
                ExtNote = new Extents2d();
                List<Extents2d> lstDic = new List<Extents2d>();
                int beamCount = 8;
                DrawingSteelTrussBeam.DrawingAverageGLNote(ref db, ref lstDic, RefPtNote, beamCount);
                #endregion

                #region 模型空间到布局空间投影处理
                LayoutTools.CreateLayout(db, "图纸", lstDic, Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, OverAllScale,1);
                Point2d tKPoint = Point2d.Origin;

                Extents2d ex = new Extents2d();
                //PictureFrameTools.AddPaperDBText(db, tKPoint, drawingConfigModel, ref ex, exfLst.Count);
                PictureFrameTools.AddPaperDBText(db, tKPoint,  drawingConfigModel, ref ex, count, page);
                #endregion


            }
            catch (Exception ex)
            {

            }
            dtProjectConfigTb = dtProjectConfig;
        }


        public void DrawingSteelTrussBeamAverageGLTable(Database db, string bridgeId, string categoryId, int page, int count, out System.Data.DataTable dtProjectConfigTb, double bridgeW, double bridgeSlope, double divCap, double divHeight, Dictionary<Tuple<string, double, double, DataRow, bool, double>, int> dicGL, List<Tuple<string, double>> tupleGLLst, ref System.Data.DataTable dtQuatity, int stNum = 0,double light_width=4500,double light_length=3000)
        {
            try
            {
                string sqlBridgeConfig = "select * from busi_project_config where bridge_id='" + bridgeId + "'";
                dtProjectConfig = MySqlHelper.ExecuteDataTable(sqlBridgeConfig, CommandType.Text);
                PictureFrameTools.GetBridgeConfig(dtProjectConfig);


                Point2d dPt1 = Point2d.Origin;
                List<Tuple<double, double, double>> tupleLst = new List<Tuple<double, double, double>>();


                #region 绘制图形
                drawingConfigModel = PictureFrameTools.GetDrawingConfig(dtBridgeDrawing, categoryId, dtProjectConfig);
                double OverAllScale = drawingConfigModel.drawing_scale;
                DrawingSteelTrussBeam bridge = new DrawingSteelTrussBeam(_bridgeId, OverAllScale);

                Extents2d ExtNote;
                Point2d RefPtNote;
                RefPtNote = Point2d.Origin;
                ExtNote = new Extents2d();

               
                DrawingSteelTrussBeam.DrawingAverageGLTable(ref db, ref ExtNote, RefPtNote, bridgeW, bridgeSlope, divCap, divHeight, dicGL, tupleGLLst, ref  dtQuatity, stNum, light_width,light_length);
                #endregion

                #region 模型空间到布局空间投影处理
                LayoutTools.CreateLayoutNew(db, "图纸", ExtNote, Extensions.leftWidth, Extensions.rightWidth, Extensions.bottomHeight, Extensions.topHeight, 1);
                Point2d tKPoint = Point2d.Origin;

                Extents2d ex = new Extents2d();
                //PictureFrameTools.AddPaperDBText(db, tKPoint, drawingConfigModel, ref ex, exfLst.Count);
                PictureFrameTools.AddPaperDBText(db, tKPoint, 0, drawingConfigModel, ref ex, page, count);
                #endregion


            }
            catch (Exception ex)
            {

            }
            dtProjectConfigTb = dtProjectConfig;
        }

    }


}
